//
//  YMRefresh.swift
//  NewVersionDemo
//
//  Created by zeng on 2018/3/15.
//  Copyright © 2018年 youmy. All rights reserved.
//

import UIKit
import MJRefresh

class YMRefresh: NSObject {
    class func headerRefresh(_ obj: Any,
                             dic:[String:String] = ["idle":"下拉可以刷新","refreshing":"松开立即刷新","noMoreData":"正在刷新数据中..."],
                             font:UIFont = UIFont.systemFont(ofSize: 11),
                             textColor:UIColor = ym_light_color,
                             _ selector:Selector)->MJRefreshNormalHeader
    {
        let header = MJRefreshNormalHeader(refreshingTarget: obj, refreshingAction: selector)
        header?.setTitle(dic["idle"], for: .idle)
        header?.setTitle(dic["pulling"], for: .pulling)
        header?.setTitle(dic["refreshing"], for: .refreshing)
        
        header?.stateLabel.font = font
        header?.stateLabel.textColor = textColor
        
        header?.lastUpdatedTimeLabel.font = font
        header?.lastUpdatedTimeLabel.textColor = textColor
        
        header?.beginRefreshing()
        return header!
    }
    
    class func footerRefresh(_ obj: Any,
                             dic:[String:String] = ["idle":"点击或上拉刷新","refreshing":"加载更多数据...","noMoreData":"没有更多了哟~"],
                             font:UIFont = UIFont.systemFont(ofSize: 11),
                             textColor:UIColor = ym_light_color,
                             _ selector:Selector)->MJRefreshAutoNormalFooter
    {
        let footer = MJRefreshAutoNormalFooter(refreshingTarget: obj, refreshingAction: selector)
        footer?.setTitle(dic["idle"], for: .idle)
        footer?.setTitle(dic["refreshing"], for: .refreshing)
        footer?.setTitle(dic["noMoreData"], for: .noMoreData)
        
        footer?.stateLabel.font = font
        footer?.stateLabel.textColor = textColor
        
        return footer!
    }
}

extension MJRefreshNormalHeader {
    func headerRefresh(_ obj: Any,
                       dic:[String:String] = ["idle":"下拉可以刷新","refreshing":"松开立即刷新","noMoreData":"正在刷新数据中..."],
                       font:UIFont = UIFont.systemFont(ofSize: 11),
                       textColor:UIColor = ym_light_color,
                       _ selector:Selector)->MJRefreshNormalHeader
    {
        let header = MJRefreshNormalHeader(refreshingTarget: obj, refreshingAction: selector)
        header?.setTitle(dic["idle"], for: .idle)
        header?.setTitle(dic["pulling"], for: .pulling)
        header?.setTitle(dic["refreshing"], for: .refreshing)
        
        header?.stateLabel.font = font
        header?.stateLabel.textColor = textColor
        
        header?.beginRefreshing()
        return header!
    }
}

extension MJRefreshAutoNormalFooter {
    func footerRefresh(_ obj: Any,
                       dic:[String:String] = ["idle":"点击或上拉刷新","refreshing":"加载更多数据...","noMoreData":"没有更多了哟~"],
                       font:UIFont = UIFont.systemFont(ofSize: 11),
                       textColor:UIColor = ym_light_color,
                       _ selector:Selector)->MJRefreshAutoNormalFooter
    {
        let footer = MJRefreshAutoNormalFooter(refreshingTarget: obj, refreshingAction: selector)
        footer?.setTitle(dic["idle"], for: .idle)
        footer?.setTitle(dic["refreshing"], for: .refreshing)
        footer?.setTitle(dic["noMoreData"], for: .noMoreData)
        
        footer?.stateLabel.font = font
        footer?.stateLabel.textColor = textColor
        
        return footer!
    }
}
